/*
 * Sesame Inc.
 * Copyright (c) 2009 All Rights Reserved.
 */
package com.sesame.daoimpl;

import java.util.List;

import org.springframework.orm.ibatis.support.SqlMapClientDaoSupport;

import com.sesame.dao.AlbumDAO;
import com.sesame.domain.Album;
import com.sesame.toolkit.Page;

/**
 * @author voidman
 * 
 */
public class AlbumDAOImpl extends SqlMapClientDaoSupport implements AlbumDAO {

    public void addAlbum(Album Album) {
        getSqlMapClientTemplate().insert("addAlbum", Album);
    }

    public void deleteAlbumById(Integer id) {
        getSqlMapClientTemplate().delete("deleteAlbumById", id);
    }

    @SuppressWarnings("unchecked")
    public List<Album> getAllAlbum() {
        return (List<Album>) getSqlMapClientTemplate().queryForList(
                "getAllAlbum");
    }

    public List<Album> getAllAlbum(Page page) {
        return (List<Album>) getSqlMapClientTemplate().queryForList(
                "getPageAlbum", page);
    }

    public Album getAlbumById(Integer id) {

        return (Album) getSqlMapClientTemplate().queryForObject("getAlbumById",
                id);
    }

    @SuppressWarnings("unchecked")
    public List<Album> getAlbumByUserId(Page page) {
        List<Album> listAlbum;
        listAlbum = getSqlMapClientTemplate().queryForList(
                "getPageAlbumByUserId", page);
        return listAlbum;
    }

    @SuppressWarnings("unchecked")
    public List<Album> getAlbumByUserId(Integer userId) {
        List<Album> listAlbum;
        listAlbum = getSqlMapClientTemplate().queryForList("getAlbumByUserId",
                userId);
        return listAlbum;
    }

    public Integer getAlbumByTitleAndUserId(Album album) {

        return (Integer) getSqlMapClientTemplate().queryForObject(
                "getAlbumByTitleAndUserId", album);
    }

    public void updateAlbum(Album album) {
        getSqlMapClientTemplate().update("updateAlbum", album);
    }

    public void updateCover(Album album) {
        getSqlMapClientTemplate().update("updateCover", album);
    }

    public Integer getAlbumCount(Integer userId) {
        return (Integer) getSqlMapClientTemplate().queryForObject(
                "getAlbumCount", userId);
    }

    public Integer getAllAlbumCount() {
        return (Integer) getSqlMapClientTemplate().queryForObject(
                "getAllAlbumCount");
    }

    public List<Album> getTopAlbumByUserId(Integer userId) {
        return (List<Album>) getSqlMapClientTemplate().queryForList(
                "getTopAlbumByUserId", userId);
    }

    public List<Album> getTopAlbum() {
        return (List<Album>) getSqlMapClientTemplate().queryForList(
                "getTopAlbum");
    }

    public void updateVisitAmount(Integer id) {
        getSqlMapClientTemplate().update("updateAlbumVisitAmount", id);
    }
}